<!DOCTYPE html>
<html lang="en"
      xmlns:th="https://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="utf-8">
    <meta name="author" content="test">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="description" content="This is a login page template based on Bootstrap 5">
    <title>Login Page</title>
    <style>
        .is-invalid {
            color: red;
        }

        .invalid-feedback {
            color: red;
        }

        .mb-3 {
            margin-bottom: 3px;
        }
    </style>
    <script th:inline="javascript">
        /*<![CDATA[*/
        // const baseURL = /*[[@{/}]]*/ ''; /*]]>*/
        if (window !== top) {
            top.location.href = location.href;
        }
    </script>
</head>
<body class="hold-transition login-page">
<div class="login-box">
    <div class="card">
        <div class="card-body login-card-body">
            <p class="login-box-msg">Sign in to start your session</p>
            <div th:if="${param.error}" class="alert alert-error">
                Invalid username and password.
            </div>
            <div th:if="${param.logout}" class="alert alert-success">
                You have been logged out.
            </div>
            <form th:action="@{/login}" method="post" id="loginForm">
                <div class="input-group mb-3">
                    <input type="text" class="form-control" value="zxg" name="username" placeholder="Email"
                           autocomplete="off">
                </div>
                <div class="input-group mb-3">
                    <input type="password" id="password" name="password" value="123" class="form-control"
                           maxlength="25" placeholder="Password"
                           autocomplete="off">
                </div>
                <div class="row">
                    <div class="col-4">
                        <button type="submit" id="submitBtn">Sign In</button>
                    </div>
                </div>
            </form>
            <p class="mb-1">
                <a href="javascript:void(0)">I forgot my password</a>
            </p>
            <p class="mb-0">
                <a href="javascript:void(0)" class="text-center">Register a new membership</a>
            </p>
        </div>
    </div>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jsencrypt/3.1.0/jsencrypt.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery-validate/1.9.0/jquery.validate.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery-validate/1.9.0/additional-methods.min.js"></script>

<script th:inline="javascript">

    $(function () {
        var encrypt = new JSEncrypt();

        $.validator.setDefaults({
            submitHandler: function (form) {
                console.log("Form successful submitted!");
                // $('#password2').removeAttr("name")
                // loading('submitBtn');
                form.submit();
            }
        });

        // $('#loginForm').validate({
        //     rules: {
        //         "username": {
        //             required: true,
        //             email: true,
        //         },
        //         "password": {
        //             required: true,
        //             minlength: 6,
        //             maxlength: 25,
        //         },
        //     },
        //     messages: {
        //         "username": {
        //             required: "Please enter a email address.",
        //             email: "Please enter a vaild email address."
        //         },
        //         "password": {
        //             required: "Please provide a password.",
        //             minlength: "Your password must be at least 16 characters long"
        //         },
        //     },
        //     errorElement: 'span',
        //     errorPlacement: function (error, element) {
        //         error.addClass('invalid-feedback');
        //         element.closest('.input-group').append(error);
        //     },
        //     highlight: function (element, errorClass, validClass) {
        //         $(element).addClass('is-invalid');
        //     },
        //     unhighlight: function (element, errorClass, validClass) {
        //         $(element).removeClass('is-invalid');
        //     }
        // });


    });
</script>
</body>
</html>
